#ifndef _DO_SQL_H_
#define _DO_SQL_H_

#include "game_log.h"
#include "game_mysql.h"
#include "json/json.h"
#include <vector>

struct S_DB_PLAYER_INFO
{
	S_DB_PLAYER_INFO() 
	{
		id =0;
		status = 0;
		user = "";
		nick_name = "";
		login_ip = "";
		robot_flag = 0;
		sex = 0;
		avater_url = "";
		diamonds = 0;
		gold = 0;
		paiwei_score= 0;
	}
	
	int id;//玩家ID
	int status;//账号状态
	std::string user;//账号
	std::string nick_name;//昵称
	std::string login_ip;//登陆IP
	int robot_flag;//机器人标志
	int sex;//性别
	std::string avater_url;//头像URL
	int diamonds;//钻石
	int gold;//金币
	int paiwei_score;
};
//获取服务器信息
int get_server_info(int server_id);
//从数据库获取用户的基础信息
int get_db_player_info(S_DB_PLAYER_INFO &db_player_info, int uid);
//修改用户的在线状态
int update_db_player_online(int uid, int if_game, int if_room, int if_online);
//扣金币
int decrease_gold(int uid, int num);
//扣钻石
int decrease_diamonds(int uid, int num);
//int init_db_player_flag(int game_flag);
//插入游戏结果
int insert_board_end_record(
	int rec_id,
	int roomid,
	int board_choose,
	int cur_board,
	int player_num,
	std::string time_str,
	int end_type,
	int fangpaiji_mj,
	int next_fangpaiji_mj,
	int uid,
	std::string nick_name,
	int seatid,
	int if_banker,
	int jiaopai_flag,
	int cur_gang_score,
	int cur_angang_score,
	int cur_minggang_score,
	int cur_fanggang_score,
	int fangpaiji_score,
	int gudingji_score,
	int chongfengji_score,
	int zherenji_score,
	int cardtype_score,
	int winlose_score,
	int score,
	int cur_pao_flag,
	int card_type,
	int fangpaiji_num,
	std::string hole_str,
	std::string fm_str,
	std::string out_str
);

//更新开房卡的状态
int update_room_ticket_status(int roomid, int status);

//绑定开房实例
int bind_room_ticket(int roomid, int server_id, int desk_id);

//房卡的信息
struct S_DB_TICKET_INFO
{
	int uid;
	int clubid;
	int player_num;		//几个人
	int board_num;		//玩几把
	int status;			//1.待使用 2.等待组局 3.已经使用 4.已经退还 0.未激活
	int pwd;			//开房密码
};

//获取这个房卡的信息
int get_room_ticket_board_num(S_DB_TICKET_INFO& info, int roomid);

//开房牌局开始时插入牌局记录
int insert_total_end_record(int roomid, int board_choose, int end_board, std::string time_str,
	int uid1, int score1,
	int uid2 = 0, int score2 = 0,
	int uid3 = 0, int score3 = 0,
	int uid4 = 0, int score4 = 0);

//开房牌局结算时更新记录
int update_total_end_record(int rec_id, int end_board,
	std::string time_str,
	int score1,int score2 = 0,int score3 = 0, int score4 = 0);

//int insert_cur_online_players(int game_flag, int num);
//增加用户金币场输赢 result 1:win 2:fail 3:peace
int increase_user_result(int uid, int result = 0);

//当前服务器的每日活跃+1
int increase_add_action(int server_id, std::string date);

//钻石改变记录
int insert_diamonds_change_rec(int uid, int change, std::string source = "", std::string comment = "");
//金币改变记录
int insert_gold_change_rec(int uid, int change, std::string source = "", std::string comment = "");
//插入排位分变化记录
int insert_paiwei_score_change_rec(int uid, int change_begin, int change, int change_end, std::string source = "排位");

//刷新某一个房间类型的当前在线人数
int update_gold_room_player_count(int server_id, int online_num);
//初始话在线人数
int init_gold_room_player_count(int server_id);
//排位分变化
int decrease_paiwei_score(int uid, int add_score);



#endif
